﻿/*
 * Created by SharpDevelop.
 * Project started:
 * Date: 2014.01.10.
 * Time: 19:27
 * -------------------------
 * [Status]
 * 5-os == 75%
 * 6-os == 75%
 * 7-es == 75%
 * Putto == 75% -Hiányzik a teljes B-mező számolás
 * Joker == 20%
 * Penz == 0%
 * Menu == 0%
 * Jegy == 0%
 * ----------
 * Osszesen == 40%
 * [/status]
 * UNDONE: Valahogy szebben jelenjenek meg a találatok
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Wheel_of_Luck
{
	enum MAX
	{
		OTOS = 90,
		HATOS = 45,
		SKANDI = 35,
		PUTTO = 20,
		PUTTO_B = 4,
	}
	enum HUZASOK
	{
		OTOS = 5,
		HATOS = 6,
		SKANDI = 7,
		PUTTO = 8,
		PUTTO_B = 1,
	}
	public partial class MainForm : Form
	{
		public int i = 0;
		public int j = 0;
		public int talalat = 0;
		public int[] result = new int[8];
		public int resultB;
		public int[] tipp = new int[8];
		public int tippB;
		public int jatekmod = 5;	
		public void SorbaRendez(ref int egyik, ref int masik)
		{
			egyik = egyik + masik;
			masik = egyik - masik;
			egyik = egyik - masik;
		}
		public void SzinezesTorles()
		{
			box_nr1.BackColor = Color.White;
			box_nr2.BackColor = Color.White;
			box_nr3.BackColor = Color.White;
			box_nr4.BackColor = Color.White;
			box_nr5.BackColor = Color.White;
			box_nr6.BackColor = Color.White;
			box_nr7.BackColor = Color.White;
			box_nr8.BackColor = Color.White;
			box_nrB.BackColor = Color.White;
		}
		public void LathatosagiSzint(int szint)
		{
			switch(szint)
			{
				case 5:
					jatekmod = 5;
					box_nr1.Visible = true;
					box_nr2.Visible = true;
					box_nr3.Visible = true;
					box_nr4.Visible = true;
					box_nr5.Visible = true;
					box_nr6.Visible = false;
					box_nr7.Visible = false;
					box_nr8.Visible = false;
					box_nrB.Visible = false;
					box_joker.Enabled = true;
					checkbox_joker.Enabled = true;
					label_PH1.Visible = true;
					label_PH2.Visible = true;
					label_PH3.Visible = true;
					label_PH4.Visible = true;
					label_PH5.Visible = true;
					label_PH6.Visible = false;
					label_PH7.Visible = false;
					label_PH8.Visible = false;
					label_PH_FIELD_B.Visible = false;
					break;
				case 6:
					jatekmod = 6;
					box_nr1.Visible = true;
					box_nr2.Visible = true;
					box_nr3.Visible = true;
					box_nr4.Visible = true;
					box_nr5.Visible = true;
					box_nr6.Visible = true;
					box_nr7.Visible = false;
					box_nr8.Visible = false;
					box_nrB.Visible = false;
					box_joker.Enabled = true;
					checkbox_joker.Enabled = true;
					label_PH1.Visible = true;
					label_PH2.Visible = true;
					label_PH3.Visible = true;
					label_PH4.Visible = true;
					label_PH5.Visible = true;
					label_PH6.Visible = true;
					label_PH7.Visible = false;
					label_PH8.Visible = false;
					label_PH_FIELD_B.Visible = false;
					break;
				case 7:
					jatekmod = 7;
					box_nr1.Visible = true;
					box_nr2.Visible = true;
					box_nr3.Visible = true;
					box_nr4.Visible = true;
					box_nr5.Visible = true;
					box_nr6.Visible = true;
					box_nr7.Visible = true;
					box_nr8.Visible = false;
					box_nrB.Visible = false;
					box_joker.Enabled = true;
					checkbox_joker.Enabled = true;
					label_PH1.Visible = true;
					label_PH2.Visible = true;
					label_PH3.Visible = true;
					label_PH4.Visible = true;
					label_PH5.Visible = true;
					label_PH6.Visible = true;
					label_PH7.Visible = true;
					label_PH8.Visible = false;
					label_PH_FIELD_B.Visible = false;
					break;
				case 8:
					jatekmod = 8;
					box_nr1.Visible = true;
					box_nr2.Visible = true;
					box_nr3.Visible = true;
					box_nr4.Visible = true;
					box_nr5.Visible = true;
					box_nr6.Visible = true;
					box_nr7.Visible = true;
					box_nr8.Visible = true;
					box_nrB.Visible = true;
					box_joker.Enabled = false;
					checkbox_joker.Enabled = false;
					label_PH1.Visible = true;
					label_PH2.Visible = true;
					label_PH3.Visible = true;
					label_PH4.Visible = true;
					label_PH5.Visible = true;
					label_PH6.Visible = true;
					label_PH7.Visible = true;
					label_PH8.Visible = true;
					label_PH_FIELD_B.Visible = true;
					break;
			}
		}
		public void TippBeolvasas(int mennyit)
		{
			try
			{
				switch(mennyit)
				{
					case 5:
						tipp[0] = int.Parse(box_nr1.Text);
						tipp[1] = int.Parse(box_nr2.Text);
						tipp[2] = int.Parse(box_nr3.Text);
						tipp[3] = int.Parse(box_nr4.Text);
						tipp[4] = int.Parse(box_nr5.Text);
						break;
					case 6:
						tipp[0] = int.Parse(box_nr1.Text);
						tipp[1] = int.Parse(box_nr2.Text);
						tipp[2] = int.Parse(box_nr3.Text);
						tipp[3] = int.Parse(box_nr4.Text);
						tipp[4] = int.Parse(box_nr5.Text);
						tipp[5] = int.Parse(box_nr6.Text);
						break;
					case 7:
						tipp[0] = int.Parse(box_nr1.Text);
						tipp[1] = int.Parse(box_nr2.Text);
						tipp[2] = int.Parse(box_nr3.Text);
						tipp[3] = int.Parse(box_nr4.Text);
						tipp[4] = int.Parse(box_nr5.Text);
						tipp[5] = int.Parse(box_nr6.Text);
						tipp[6] = int.Parse(box_nr7.Text);
						break;
					case 8:
						tipp[0] = int.Parse(box_nr1.Text);
						tipp[1] = int.Parse(box_nr2.Text);
						tipp[2] = int.Parse(box_nr3.Text);
						tipp[3] = int.Parse(box_nr4.Text);
						tipp[4] = int.Parse(box_nr5.Text);
						tipp[5] = int.Parse(box_nr6.Text);
						tipp[6] = int.Parse(box_nr7.Text);
						tipp[7] = int.Parse(box_nr8.Text);
						tippB = int.Parse(box_nrB.Text);
						break;
				}
			}
			catch
			{
				box_results.Text = "Tipp beolvasási hiba.";
			}
		}
		public void TalalatEllenorzes(int mennyit)
		{
			talalat = 0;
			for(i = 0; i < mennyit; ++i)
			{
				for(j = 0; j < mennyit; ++j)
				{
					if(result[i] == tipp[j]) //FIXME
					{
						talalat++;
						try
						{
							switch (jatekmod)
							{
							case 5:
									if(int.Parse(box_nr1.Text) == result[i])
									box_nr1.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr2.Text) == result[i])
									box_nr2.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr3.Text) == result[i])
									box_nr3.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr4.Text) == result[i])
									box_nr4.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr5.Text) == result[i])
									box_nr5.BackColor = Color.GreenYellow;
									break;
							case 6:
									if(int.Parse(box_nr1.Text) == result[i])
									box_nr1.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr2.Text) == result[i])
									box_nr2.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr3.Text) == result[i])
									box_nr3.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr4.Text) == result[i])
									box_nr4.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr5.Text) == result[i])
									box_nr5.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr6.Text) == result[i])
									box_nr6.BackColor = Color.GreenYellow;
									break;
							case 7:
									if(int.Parse(box_nr1.Text) == result[i])
									box_nr1.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr2.Text) == result[i])
									box_nr2.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr3.Text) == result[i])
									box_nr3.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr4.Text) == result[i])
									box_nr4.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr5.Text) == result[i])
									box_nr5.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr6.Text) == result[i])
									box_nr6.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr7.Text) == result[i])
									box_nr7.BackColor = Color.GreenYellow;
									break;
							case 8:
									if(int.Parse(box_nr1.Text) == result[i])
									box_nr1.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr2.Text) == result[i])
									box_nr2.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr3.Text) == result[i])
									box_nr3.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr4.Text) == result[i])
									box_nr4.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr5.Text) == result[i])
									box_nr5.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr6.Text) == result[i])
									box_nr6.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr7.Text) == result[i])
									box_nr7.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nr8.Text) == result[i])
									box_nr8.BackColor = Color.GreenYellow;
									else if(int.Parse(box_nrB.Text) == result[i])
									box_nrB.BackColor = Color.GreenYellow;
									break;
							}
						}
						catch
						{
							box_results.Text = "Error";
						}
					}
				}
			}
			box_results.Text = box_results.Text+"\r\n Találatok száma: "+talalat;			
		}
		/*public void AzonosTetVizsgalat(int mennyit) FIXME: Ezt mindig egy mező változásánál kell ellenőrizni
		{
			for(i = 0; i < mennyit; ++i)
			{
				for(j = 0; j < mennyit ++j)
				{
					if(tipp[i] == tipp[j])
					{
						try
						{
							switch (jatekmod)
							{
							case 5:
									if(int.Parse(box_nr1.Text) == result[i])
									box_nr1.BackColor = Color.Red;
									else if(int.Parse(box_nr2.Text) == result[i])
									box_nr2.BackColor = Color.Red;
									else if(int.Parse(box_nr3.Text) == result[i])
									box_nr3.BackColor = Color.Red;
									else if(int.Parse(box_nr4.Text) == result[i])
									box_nr4.BackColor = Color.Red;
									else if(int.Parse(box_nr5.Text) == result[i])
									box_nr5.BackColor = Color.Red;
									break;
							case 6:
									if(int.Parse(box_nr1.Text) == result[i])
									box_nr1.BackColor = Color.Red;
									else if(int.Parse(box_nr2.Text) == result[i])
									box_nr2.BackColor = Color.Red;
									else if(int.Parse(box_nr3.Text) == result[i])
									box_nr3.BackColor = Color.Red;
									else if(int.Parse(box_nr4.Text) == result[i])
									box_nr4.BackColor = Color.Red;
									else if(int.Parse(box_nr5.Text) == result[i])
									box_nr5.BackColor = Color.Red;
									else if(int.Parse(box_nr6.Text) == result[i])
									box_nr6.BackColor = Color.Red;
									break;
							case 7:
									if(int.Parse(box_nr1.Text) == result[i])
									box_nr1.BackColor = Color.Red;
									else if(int.Parse(box_nr2.Text) == result[i])
									box_nr2.BackColor = Color.Red;
									else if(int.Parse(box_nr3.Text) == result[i])
									box_nr3.BackColor = Color.Red;
									else if(int.Parse(box_nr4.Text) == result[i])
									box_nr4.BackColor = Color.Red;
									else if(int.Parse(box_nr5.Text) == result[i])
									box_nr5.BackColor = Color.Red;
									else if(int.Parse(box_nr6.Text) == result[i])
									box_nr6.BackColor = Color.Red;
									else if(int.Parse(box_nr7.Text) == result[i])
									box_nr7.BackColor = Color.Red;
									break;
							case 8:
									if(int.Parse(box_nr1.Text) == result[i])
									box_nr1.BackColor = Color.Red;
									else if(int.Parse(box_nr2.Text) == result[i])
									box_nr2.BackColor = Color.Red;
									else if(int.Parse(box_nr3.Text) == result[i])
									box_nr3.BackColor = Color.Red;
									else if(int.Parse(box_nr4.Text) == result[i])
									box_nr4.BackColor = Color.Red;
									else if(int.Parse(box_nr5.Text) == result[i])
									box_nr5.BackColor = Color.Red;
									else if(int.Parse(box_nr6.Text) == result[i])
									box_nr6.BackColor = Color.Red;
									else if(int.Parse(box_nr7.Text) == result[i])
									box_nr7.BackColor = Color.Red;
									else if(int.Parse(box_nr8.Text) == result[i])
									box_nr8.BackColor = Color.Red;
									else if(int.Parse(box_nrB.Text) == result[i])
									box_nrB.BackColor = Color.Red;
									break;
							}
						}
						catch
						{
							box_results.Text = "Error";
						}
					}
				}
			}
		}*/
		public void Sorsolas(int mennyit, int legnagyobb)
		{
			Random rng = new Random();
			for(i = 0; i < mennyit; ++i)
			{
				result[i] = rng.Next(1, legnagyobb);
				for(j = 0; j < i; ++j)
				{
					while(result[i] == result[j])
					{
						result[i] = rng.Next(1, legnagyobb);
					}
				}
			}
			int[] inputArray = new int[8];
			for(i = 0; i < mennyit; ++i)
			{
				inputArray[i] = result[i];
			}
			
			for (int iterator = 0; iterator < inputArray.Length; iterator++)
			{
				for (int index = 0; index < inputArray.Length - 1; index++)
				{
					if (inputArray[index] > inputArray[index + 1])
					{
						SorbaRendez(ref inputArray[index], ref inputArray[index+1]);
					}
				}
			}

			for(i = 0; i < mennyit; ++i)
			{
				result[i] = inputArray[i+(8-mennyit)];
			}
			box_results.Text = box_results.Text + "\r\nSorsolás: ";
			for(i = 0; i < mennyit; ++i)
				box_results.Text = box_results.Text + result[i]+", ";
			if(jatekmod == 8)
			{
				resultB = rng.Next(1, (int)MAX.PUTTO_B);
				box_results.Text = box_results.Text + "\r\nB mező: "+resultB;
			}
			
		}
		public void GepiJoker()
		{
			Random rng = new Random();
			int jokerszam = 0;
			jokerszam = rng.Next(100000, 999999);
			box_joker.Text ="" + jokerszam; //Sajat jokerszam!
		}
		public MainForm()
		{
			InitializeComponent();
			LathatosagiSzint(5); //5-os lotto a default
		}
		
		void Button_otosCheckedChanged(object sender, EventArgs e)
		{
			LathatosagiSzint(5);
		}
		
		void Button_hatosCheckedChanged(object sender, EventArgs e)
		{
			LathatosagiSzint(6);
		}
		
		void Button_skandinavCheckedChanged(object sender, EventArgs e)
		{
			LathatosagiSzint(7);
		}
		
		void Button_puttoCheckedChanged(object sender, EventArgs e)
		{
			LathatosagiSzint(8);
		}
		
		void Button_sorsolasClick(object sender, EventArgs e)
		{
			SzinezesTorles();
			box_results.Text = "";
			switch(jatekmod)
			{
				case 5:
					TippBeolvasas((int)HUZASOK.OTOS);
					Sorsolas((int)HUZASOK.OTOS,(int)MAX.OTOS);
					break;
				case 6:
					TippBeolvasas((int)HUZASOK.HATOS);
					Sorsolas((int)HUZASOK.HATOS,(int)MAX.HATOS);
					break;
				case 7:
					TippBeolvasas((int)HUZASOK.SKANDI);
					Sorsolas((int)HUZASOK.SKANDI,(int)MAX.SKANDI);
					break;
				case 8:
					TippBeolvasas((int)HUZASOK.PUTTO);
					Sorsolas((int)HUZASOK.PUTTO,(int)MAX.PUTTO);
					break;
			}
			TalalatEllenorzes(jatekmod);
		}
	}
}
